<?php


namespace App\Services;


use App\Models\RentAndPurchase;
use App\Models\WxUser;
use App\Tools\JsonTools;
use App\Tools\RedisTools;

class CacheServices
{
                 public $redis;
                 public function __construct()
                 {
                     $this->redis=RedisTools::getInstance()->connectRedis();
                 }

                /**
                 * @Notes:
                 * @Author: 遇见
                 * @Date: 2022/11/30
                 * @Time: 13:37
                 * @param $param
                 * @return array
                 * 获取缓存service操作
                 * 1.本地记录缓存
                 * 2.读取redis存储的数据进行前端渲染
                 */
                 public function cacheServices($param){
                    $array = explode("+",$param);
                    $list=array_unique($array);
                    foreach ($list as $k=>$v){
                        if($v==""){
                            unset($list[$k]);
                        }
                    }
                    $lists=[];
                    foreach ($list as $k=>$value){
                       $redis= $this->redis->hGet('RentAndPurchase',$value);
                       $redisList=json_decode($redis,true);
                       $lists[]=$redisList;
                    }
                    if(!empty($lists)){
                        return JsonTools::JsonSuccess($lists);
                    }else{
                        return JsonTools::JsonError([],2001,
                        '失败');
                    }
                }
}
